import java.util.*;

/**
 * @author LKQ
 * @date 2022/4/12 9:11
 * @description 递归
 */
public class Solution2 {
    public static void main(String[] args) {
        Solution2 solution2 = new Solution2();
        ListNode head = new ListNode(2, new ListNode(3, new ListNode(4, new ListNode(5))));
        solution2.swapPairs(head);
    }
    public ListNode swapPairs(ListNode head) {
        if (head == null || head.next == null) {
            return head;
        }
        ListNode newHead = head.next;
        // 旧的头节点 指向已经交换好的下一个节点
        head.next = swapPairs(newHead.next);
        // 新的头节点指向旧的头节点
        newHead.next = head;
        return newHead;
    }
}
